<template>
  <div o-Container>
    <o-list v-bind:source="list.sensor"
            v-bind="{modified:modify,searched:search,exported:output}"/>
    <o-dialog v-bind:source="panel" v-bind="{opened:load,closed:load}">
      <template slot="content">
        <o-item v-bind:source="item.sensor" v-bind="{saved:save,backed:back}"></o-item>
      </template>
    </o-dialog>


    <el-drawer title="我是标题" :visible.sync="drawer" :with-header="false" size="320px">
      <div style="line-height: 3.2vh;padding: 15px;">
        <div><span style="font-weight: 700;margin-right: 20px;">设备ID: </span>{{ powerData.SensorID }}</div>
        <div><span style="font-weight: 700;margin-right: 20px;">A线电压380V，相线+相线: </span>{{ powerData.LineVoltageA }}</div>
        <div><span style="font-weight: 700;margin-right: 20px;">B线电压: </span>{{ powerData.LineVoltageB }}</div>
        <div><span style="font-weight: 700;margin-right: 20px;">C线电压: </span>{{ powerData.LineVoltageC }}</div>
        <div><span style="font-weight: 700;margin-right: 20px;">A相电压220V，缺相，相电和零线: </span>{{ powerData.VoltageA }}</div>
        <div><span style="font-weight: 700;margin-right: 20px;">B相电压: </span>{{ powerData.VoltageB }}</div>
        <div><span style="font-weight: 700;margin-right: 20px;">C相电压: </span>{{ powerData.VoltageC }}</div>
        <div><span style="font-weight: 700;margin-right: 20px;">A电流: </span>{{ powerData.ElectricityA }}</div>
        <div><span style="font-weight: 700;margin-right: 20px;">B电流: </span>{{ powerData.ElectricityB }}</div>
        <div><span style="font-weight: 700;margin-right: 20px;">C电流: </span>{{ powerData.ElectricityC }}</div>
        <div><span style="font-weight: 700;margin-right: 20px;">频率: </span>{{ powerData.Frequency }}</div>
        <div><span style="font-weight: 700;margin-right: 20px;">功率因数A: </span>{{ powerData.PowerFactorA }}</div>
        <div><span style="font-weight: 700;margin-right: 20px;">功率因数B: </span>{{ powerData.PowerFactorB }}</div>
        <div><span style="font-weight: 700;margin-right: 20px;">功率因数C: </span>{{ powerData.PowerFactorC }}</div>
        <div><span style="font-weight: 700;margin-right: 20px;">总功率因数: </span>{{ powerData.TotalPowerFactor }}</div>
        <div><span style="font-weight: 700;margin-right: 20px;">有功功率A: </span>{{ powerData.ActivePowerA }}</div>
        <div><span style="font-weight: 700;margin-right: 20px;">有功功率B: </span>{{ powerData.ActivePowerB }}</div>
        <div><span style="font-weight: 700;margin-right: 20px;">有功功率C: </span>{{ powerData.ActivePowerC }}</div>
        <div><span style="font-weight: 700;margin-right: 20px;">总有功功率: </span>{{ powerData.TotalActivePower }}</div>
        <div><span style="font-weight: 700;margin-right: 20px;">无功功率A: </span>{{ powerData.ReactivePowerA }}</div>
        <div><span style="font-weight: 700;margin-right: 20px;">无功功率B: </span>{{ powerData.ReactivePowerB }}</div>
        <div><span style="font-weight: 700;margin-right: 20px;">无功功率C: </span>{{ powerData.ReactivePowerC }}</div>
        <div><span style="font-weight: 700;margin-right: 20px;">总无功功率: </span>{{ powerData.TotalReactivePower }}</div>
        <div><span style="font-weight: 700;margin-right: 20px;">视在功率A:</span> {{ powerData.ApparentPowerA }}</div>
        <div><span style="font-weight: 700;margin-right: 20px;">视在功率B: </span>{{ powerData.ApparentPowerB }}</div>
        <div><span style="font-weight: 700;margin-right: 20px;">视在功率C:</span> {{ powerData.ApparentPowerC }}</div>
        <div><span style="font-weight: 700;margin-right: 20px;">总视在功率: </span>{{ powerData.TotalApparentPower }}</div>
        <div><span style="font-weight: 700;margin-right: 20px;">总有功电能: </span>{{ powerData.TotalPower }}</div>
        <div><span style="font-weight: 700;margin-right: 20px;">正向有功电能: </span>{{ powerData.ImportPower }}</div>
        <div><span style="font-weight: 700;margin-right: 20px;">反向有功电能: </span>{{ powerData.ExportPower }}</div>

      </div>
    </el-drawer>
  </div>
</template>

<script>
  export default {
    name: "mms_iot_sensor_list", /* 这个name暂时不知道用啥用，根据官方文档说的是方便排错的 */
    data() {
      return {
        octopus: this.$parent.octopus,
        list: {
          sensor: {
            data: {
              id: 391, // 菜单表的八爪鱼ID
              cellData: [
                {name: "IsOnline", width: 70, searchKey: "="},
                {name: "ServerID", width: 110, searchKey: "=", link: [{mapping: "TypeID", value: 8}]},
                {name: "CompanyID", width: 100, searchKey: "=", filterKey: "="},
                {
                  name: "ProjectID",
                  width: 120,
                  searchKey: "=",
                  filterKey: "=",
                  link: [{binding: "CompanyID", mapping: "CompanyID"}]
                },
                { name: "AreaID" , width: 140, searchKey: "=", link: [{ binding: "ProjectID", mapping: "ProjectID" }]},	// 所属区域
                {name: "BuildingID", width: 130, searchKey: "=", link: [{binding: "AreaID", mapping: "AreaID"}]},
                {name: "FloorID", width: 70, searchKey: "=", link: [{binding: "BuildingID", mapping: "BuildingID"}]},
                {name: "BerthID", width: 90, searchKey: "=", link: [{binding: "FloorID", mapping: "FloorID"}]},
                {name: "FatherID", width: 330,searchKey:'='},
                {name: "Code", width: 330, searchKey: "LIKE"},
                {name: "Name", width: 330, searchKey: "LIKE"},
                {name: "NFCCode", show: false, width: 130, searchKey: "LIKE"},
                {name: "TypeID", width: 80, searchKey: "="},
                {name: "BrandID", width: 150, searchKey: "="},
                // {name: "AEPCode", width: 240, searchKey: "LIKE"},
                {name: "SpaceID", width: 70, searchKey: "="},
                {name: "SystemID", show: false, filterKey: "="},
                {name: "SystemModuleID", width: 140, searchKey: "="},
                {name: "IsRule", width: 60, searchKey: "="},
                {name: "RuleList", width: 200},
                {name: "Electricity_RatedPower", show: false},	      // 额定功率
                {name: "Electricity_ContractPower", show: false},	    // 合同功率
                {name: "Electricity_IsIncreaseApacity", show: false},	// 是否增容
                {name: "Electricity_IncreaseApacity", show: false},	  // 增容量
                {name: "Electricity_LineLoss", show: false},	        // 电路线损值
                {name: "Electricity_Magnification", show: false},	    // 电表倍率
                {name: "Electricity_PriceTemplateID", searchKey: "="},	  // 电能耗计费模版
                {name: "LastUpdateDate", width: 150},
                {name: "CreateTime", width: 160},
              ]
            },
          },
        },
        item: {
          sensor: {
            // 以下参数默认由组件内部创建，但是如果有需要，开发人员可在这里提前设置，组件将按照您的预期渲染。
            // cache: false,
            // control: null,
            // dataExtend: null,
            data: {
              id: 64,
              value: "",
              cellData: [
                {name: "BerthID"},
                {name: "UniqueCode"},
                {name: "ServerID"},
                {name: "FatherID"},
                {name: "Code"},
                {name: "Name"},
                {name: "NFCCode"},
                {name: "AEPCode"},
                {name: "SpaceID"},
                {name: "SystemModuleID"},
                {name: "TypeID"},
                {name: "IsRule"},
                {name: "RuleList"},
                {name: "IPAddress"},
                {name: "MacAddress"},
                {name: "BrandID"},
                {name: "CreateTime"},
                {name: "XAxis", show: false},
                {name: "YAxis", show: false},
                {name: "ZAxis", show: false},
                {name: "Electricity_RatedPower", show: false},	      // 额定功率
                {name: "Electricity_ContractPower", show: false},	    // 合同功率
                {name: "Electricity_IsIncreaseApacity", show: false},	// 是否增容
                {name: "Electricity_IncreaseApacity", show: false},	  // 增容量
                {name: "Electricity_LineLoss", show: false},	        // 电路线损值
                {name: "Electricity_Magnification", show: false},	    // 电表倍率
                {name: "Electricity_PriceTemplateID"},	  // 电能耗计费模版
                {name: "Water_LineLoss", show: false},	              // 水管线损
              ]
            },
            button: [{ class: "warning", click: this.look, text: "查看" }]
          },
        },
        panel: {
          visible: false,
        },
        powerData: [],
        drawer: false,
      }
    },
    created: function () {
      this.init();
    },
    methods: {

      look() {
        this.drawer = true
      },
      init: function () {
        let url = this.octopus.vue.$route.path;
        // MMS
        if (url.indexOf("MMS/IoT/Sensor/") > 0) {
          // this.octopus.tools.parseCell(this.list.building.data, "ProjectID").filterValue = this.octopus.passport.project;//默认筛选当前登录的小区
          // this.octopus.tools.parseCell(this.list.building.data, "ProjectID").show = false;
          // this.octopus.tools.parseCell(this.list.building.data, "CompanyID").show = false;
        }
        // MDM
        else {
          // alert(this.octopus.passport.project);
          this.octopus.tools.parseCell(this.list.sensor.data, "ProjectID").show = false;
          this.octopus.tools.parseCell(this.list.sensor.data, "ProjectID").filterValue = this.octopus.passport.project;

          this.octopus.tools.parseCell(this.list.sensor.data, "BuildingID").link = [{
            mapping: "ProjectID",
            value: this.octopus.passport.project
          }];
        }


        // 针对不同场景进行定制。
        // 电场景
        if (url.indexOf("Space/ElectricityList") > 0) {
          this.octopus.tools.parseCell(this.item.sensor.data, "XAxis").show = true;
          this.octopus.tools.parseCell(this.item.sensor.data, "YAxis").show = true;
          this.octopus.tools.parseCell(this.item.sensor.data, "ZAxis").show = true;
          this.octopus.tools.parseCell(this.item.sensor.data, "Electricity_RatedPower").show = true;        // 额定功率
          this.octopus.tools.parseCell(this.item.sensor.data, "Electricity_ContractPower").show = true;     // 合同功率
          this.octopus.tools.parseCell(this.item.sensor.data, "Electricity_IsIncreaseApacity").show = true; // 是否增容
          this.octopus.tools.parseCell(this.item.sensor.data, "Electricity_IncreaseApacity").show = true;   // 增容量
          this.octopus.tools.parseCell(this.item.sensor.data, "Electricity_LineLoss").show = true;          // 电路线损值
          this.octopus.tools.parseCell(this.item.sensor.data, "Electricity_Magnification").show = true;     // 电表倍率
          this.octopus.tools.parseCell(this.item.sensor.data, "Electricity_PriceTemplateID").show = true;   // 电能耗计费模版
          this.octopus.tools.parseCell(this.list.sensor.data, "Electricity_Magnification").show = true;   // 电表倍率

          this.octopus.tools.parseCell(this.list.sensor.data, "SystemID").filterValue = 7;
        }
        // 水场景
        else if (url.indexOf("Space/WaterList") > 0) {
          this.octopus.tools.parseCell(this.list.sensor.data, "SystemID").filterValue = 8;
        }
        // 环境
        else if (url.indexOf("Space/EnvironmentList") > 0) {
          this.octopus.tools.parseCell(this.list.sensor.data, "SystemID").filterValue = 6;
        }
        // 穿戴
        else if (url.indexOf("Space/WearSensorList") > 0) {
          this.octopus.tools.parseCell(this.list.sensor.data, "SystemID").filterValue = 12;
        }
        // 消防
        else if (url.indexOf("Space/FireList") > 0) {
          this.octopus.tools.parseCell(this.list.sensor.data, "SystemID").filterValue = 3;
        }
        // 安防
        else if (url.indexOf("Space/SecurityList") > 0) {
          this.octopus.tools.parseCell(this.list.sensor.data, "SystemID").filterValue = 13;
        }


      },
      output: function (data) {
        // 核心思想是cellData包含search数据（不管有没有），回传以后发送export指令，后台api会直接返回导出的数据提供下载。
      },
      search: function (cell) {

      },
      output: function (data) {
        // 导出以后，回调这里给客户端操作。
        // 核心思想是cellData包含search数据（不管有没有），回传以后发送export指令，后台api会直接返回导出的数据提供下载。
        // alert("export: 传感器表导出成功： " + JSON.stringify(data));
      },
      modify: function (row) {
        this.item.sensor.data.value = row.ID; //赋值
        this.item.sensor.control.load(); //刷新

        this.panel.visible = true; //打开

        const o = this;
      this.octopus.request.api.post(
        "/Octopus/Engine/List",
        {
          id: 648,
          cellData: [
            { name: "ActivePowerA" },	// 有功功率A
            { name: "ActivePowerB" },	// 有功功率B
            { name: "ActivePowerC" },	// 有功功率C
            { name: "ApparentPowerA" },	// 视在功率A
            { name: "ApparentPowerB" },	// 视在功率B
            { name: "ApparentPowerC" },	// 视在功率C
            { name: "CreateDate" },	// CreateDate
            { name: "Data" },	// Data
            { name: "ElectricityA" },	// A电流
            { name: "ElectricityB" },	// B电流
            { name: "ElectricityC" },	// C电流
            { name: "ExportPower" },	// 反向有功电能
            { name: "Frequency" },	// 频率
            { name: "ID" },	// ID
            { name: "ImportPower" },	// 正向有功电能
            { name: "LineVoltageA" },	// A线电压380V，相线+相线
            { name: "LineVoltageB" },	// B线电压
            { name: "LineVoltageC" },	// C线电压
            { name: "PowerFactorA" },	// 功率因数A
            { name: "PowerFactorB" },	// 功率因数B
            { name: "PowerFactorC" },	// 功率因数C
            { name: "ReactivePowerA" },	// 无功功率A
            { name: "ReactivePowerB" },	// 无功功率B
            { name: "ReactivePowerC" },	// 无功功率C
            { name: "SensorID" },	// SensorID
            { name: "TotalActivePower" },	// 总有功功率
            { name: "TotalPower" },	// 总有功电能
            { name: "TotalPowerFactor" },	// 总功率因数
            { name: "TotalReactivePower" },	// 总无功功率
            { name: "VoltageA" },	// A相电压220V，缺相，相电和零线
            { name: "VoltageB" },	// B相电压
            { name: "VoltageC" },	// C相电压
            { name: "TotalApparentPower" },	// 总视在功率
          ],
          paramData: {
            month: this.octopus.tools.dateFormat(new Date(), "yyyyMM"),
            code: row.Code
          },
        },
        function (data) {
          if (data.status.code == 200) {
            o.powerData = data.content.queryData[0]
          } else {
            o.octopus.tips.error(data);
          }
        }
      );
      },
      view: function (row) {
        alert("view key: " + JSON.stringify(row)); //提示
      },
      del: function (row) {
        alert("del key: " + JSON.stringify(row)); //提示
      },
      save: function () {
        // 刷新list
        this.list.sensor.control.load();
        this.back(); //后退
      },
      back: function () {
        this.panel.visible = false; // 取消
      }
    },
    props: ["oData"] //数据
  }
</script>
